package com.eryos.gwt.estate.client.mvp;

import com.eryos.gwt.estate.client.activity.ErrorActivity;
import com.eryos.gwt.estate.client.activity.HomeActivity;
import com.eryos.gwt.estate.client.factory.ClientFactory;
import com.eryos.gwt.estate.client.place.ErrorPlace;
import com.eryos.gwt.estate.client.place.HomePlace;
import com.eryos.gwt.estate.moduleA.client.activity.ModuleAActivity;
import com.eryos.gwt.estate.moduleA.client.place.ModuleAPlace;
import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;

/**
 * ActivityMapper maps each Place to its corresponding Activity.
 * 
 * @author combeol
 * @version $Revision$
 */
public class AppActivityMapper implements ActivityMapper {

    private final ClientFactory clientFactory;

    /**
     * AppActivityMapper associates each Place with its corresponding {@link Activity}.
     * 
     * @param clientFactory
     *            Factory to be passed to activities
     */
    public AppActivityMapper(ClientFactory clientFactory) {
        super();
        this.clientFactory = clientFactory;
    }

    /**
     * Map each Place to its corresponding Activity. This would be a great use for GIN.
     */
    @Override
    public Activity getActivity(Place place) {

        /************ All Places ************/
        if (place instanceof HomePlace) {
            return new HomeActivity((HomePlace) place, clientFactory);
        }
        if (place instanceof ErrorPlace) {
            return new ErrorActivity((ErrorPlace) place, clientFactory);
        }
        if (place instanceof ModuleAPlace) {
            return new ModuleAActivity((ModuleAPlace) place, clientFactory);
        }

        // Default Place (Home)
        return new HomeActivity((HomePlace) place, clientFactory);
    }

}
